<template>
	<view class="shop">
		<image class="img_background" src="@/static/images/shop_background.png" mode=""></image>
		<view class="shop_main" :style="[style]">
			<view class="nav_list">
				<u-tabs :list="navList" height='88' active-color='#26C281' inactive-color='#222222' :is-scroll="false"
					:current="current" :font-size="28" @change="navChange"></u-tabs>
			</view>
			
			<view class="search_box">
										 <u-collapse>
										 		<u-collapse-item :title="sousuo">
				<u-form>
					<u-form-item>
						<u-input placeholder="请输入订购号码" v-model="phone" maxlength="11" border></u-input>
					</u-form-item>
					<u-form-item>
						<u-input placeholder="请输入姓名" v-model="shipping_contact"  maxlength="40" border></u-input>
					</u-form-item>
					<u-form-item>
						<u-input placeholder="请输入电话" v-model="shipping_phone"  maxlength="11" border></u-input>
					</u-form-item>
					<u-form-item>
						<u-input placeholder="请输入产品名称" v-model="package_name"  maxlength="40" border></u-input>
					</u-form-item>
					<!-- <u-form-item>
						<u-input placeholder="请输入代理名称" v-model="user_name"  maxlength="40" border></u-input>
					</u-form-item> -->
					<u-form-item>
						<view class="btn_box">
							<u-button shape="circle" type="error" class="btn reset" @click="reset">重置</u-button>
							<u-button shape="circle" class="btn confirm" @click="confirm">查询</u-button>
						</view>
					</u-form-item>
				</u-form>
										</u-collapse-item>
										</u-collapse>
			</view>

			<view class="order-list">

				<view class="order-item" v-for="(item,index) in list" :key="index">
					<view class="header">
						<text class="pro-title">{{item.packages.name}}</text>
						<view class="status a" v-if="item.order_status == 0">已取消</view>
						<view class="status b" v-if="item.order_status == 1">已激活</view>
						<view class="status c" v-if="item.order_status == 2">待收货</view>
						<view class="status d" v-if="item.order_status == 3">待处理</view>
						<view class="status e" v-if="item.order_status == 4">待付款</view>
						<view class="status e" v-if="item.order_status == 5">已结算</view>
					</view>
					<view class="main box-border">
						<view class="cell" @click.stop="copyBtn(item.order_id)"><text>订单编号：{{item.order_id}}</text></view>
						<view class="cell"><text>{{item.shipping_contact}}</text><text>{{item.shipping_idcard}}</text></view>
						<view class="cell" @click.stop="copyBtn(item.phone)"><text>订购号码：{{item.phone}}</text></view>
						<view class="cell"><text>联系地址：{{item.shipping_province}}{{item.shipping_city}}{{item.shipping_area}}{{item.shipping_address}}</text></view>
						<view class="cell" @click.stop="copyBtn(item.shipping_phone)"><text>联系电话：{{item.shipping_phone}}</text></view>
						<view class="cell" ><text>下单时间：{{item.createtime_text}}</text></view>
						<view class="cell" ><text>代理名称：{{item.username}}</text></view>
						<view class="cell" v-if="item.level !=0"><text>代理层级：{{item.level}}</text></view>
						<view class="cell" style="display: flex; align-items: center;" v-show="item.order_status <=3">
							<text v-if="item.baoxiao_status == 0 && item.audit_status == 0 && item.packages.card_type == 1" style="color: #26c281;">请上传充值详情截图：</text>
							<text v-if="item.baoxiao_status == 0 && item.audit_status == 0 && item.packages.card_type == 2" style="color: red;">
								<text v-if="item.packages.pay_channel == 1">
									请确认您激活的充值号码
								</text>
								<text v-else>
									请确认激活号码并上传充值二维码
								</text>
							</text>
							<text v-if="item.image_text">截图凭证：</text>
							<text v-if="item.audit_status == 3">因{{item.reason}}原因审核未通过，请重新提交：</text>
							<image v-if="item.image_text" style="width: 90rpx; height: 90rpx;" :src="item.image_text" @click="previewImage(item.image_text)"></image>
							<text v-if="item.admin_image_text">充值凭证：</text>
							<image v-if="item.admin_image_text" style="width: 90rpx; height: 90rpx;" :src="item.admin_image_text" @click="previewImage(item.admin_image_text)"></image>
							
							<u-upload 
								v-if="item.order_status <=3 && item.packages.card_type == 1 && item.audit_status == 0 || item.audit_status == 3"
								:show-upload-list="false"
								:action="action" 
								:header="header" 
								custom-btn @on-success="(e) => onSuccess(e, item)">
								<view slot="addBtn" class="upload-btn" hover-stay-time="150" style="color: red;">上传截图</view>
							</u-upload>
							
							<text class="cell" v-if="item.order_status <=3 && item.packages.card_type == 2 &&  item.audit_status == 0 || item.audit_status == 3" style="color: red;" @click="uploadBtn(item.id,item.packages.pay_channel,item.phone)">上传</text>
							
						</view>
					</view>
					<view class="footer">
						<text class="left" v-if="item.order_status == 0">失败原因:{{item.remark}}</text>
						<text class="left" v-if="item.order_status == 5">佣金:{{item.user_rebate}}</text>
						<text class="right" v-if="item.order_status == 5">{{item.settlement_time_text}}</text>
						<text class="right" v-if="item.order_status == 4">本单将于{{item.jiesuan_time_text}}结算</text>
						<text class="right" v-if="item.order_status == 1">{{item.packages.demand}}</text>
						<text class="left" @click.stop="copyBtn(item.shipping_company_name)" v-if="item.order_status == 2 && item.shipping_company_name">{{item.shipping_company_name}}</text>
						<text class="right" @click.stop="copyBtn(item.shipping_no)" v-if="item.order_status == 2 && item.shipping_no">{{item.shipping_no}}</text>
						<!-- <text class="right" v-if="item.order_status == 3">下单时间：{{item.createtime_text}}</text> -->
					</view>
					<view class="footer">
						<text class="left" v-if="item.order_status == 5 && item.rebate_recover_msg">追回原因:{{item.rebate_recover_msg}}</text>
						<text class="right" v-if="item.order_status == 5 && item.rebate_recover_msg">追回金额:{{item.rebate_recover_money}}</text>
					</view>
				</view>
			</view>
		</view>
		<UploadPayment ref="upPayment" @submit='submitBtn'></UploadPayment>
		<!-- 温馨提示 -->
		<u-popup v-model="show" mode="center" border-radius="16" width="590rpx" height="400rpx">
			<view class="shop_box">
				<view class="title">温馨提示</view>
				<view class="text" v-if="type==1">您的团队成员人数不符合升级要求，暂时不能申请！</view>
				<view class="text" v-if="type==2">您没有权限使用，只有店长、副店长、管理员才可以使用！</view>
				<view class="text" v-if="type==3">申请已提交，请耐心等待审核！</view>
				<view class="btn">
					<text class="btn_right" @click="show=false">确定</text>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import baseVal from '@/config/base.js'
	import PayInfo from '@/components/pay_info/pay_info.vue';
	import UploadPayment from '@/components/upload_payment/upload_payment.vue';
	import ConfirmReceipt from '@/components/confirm_receipt/confirm_receipt.vue';
	let baseUrl;
	if (process.env.NODE_ENV === 'development') {
		baseUrl = baseVal.devUrl // 开发环境
	} else {
		baseUrl = baseVal.baseUrl // 生产环境
	}
	import {
		mapState
	} from 'vuex';
	export default {
		components:{
			PayInfo,UploadPayment,ConfirmReceipt
		},
		data() {
			
			return {
				header: {
					token: uni.getStorageSync('token')
				},
				action: baseUrl + '/api/Common/upload',
				topNumber: 0,
				// 
				is_dl:true,
				navList: [ 
					{
						name: '全部'
					},
					{
					name: '待处理'
				}, {
					name: '待收货'
				}, {
					name: '待充值'
				}, {
					name: '待结算'
				},
				{
					name: '已结算'
				},
				{
					name: '失败'
				}
				],
				package_name:'',
				shipping_contact:'',
				shipping_phone:'',
				phone:'',
				sousuo:"搜索",
				current: 0,
				shop_name: '--',
				ljsy: '--',
				score: "--",
				commission: '--',
				morning: 2,
				morning_time: '--',
				afternoon: 2,
				afternoon_time: '--',
				ljmhe: '',
				sell_num: '',
				ljxf_score: '',
				lscs: '',
				// 弹框
				type: 1,
				show: false,
				user_info: {},
				spread: '',
				page:1,
				list:[],
				current2:-1,
				package_name: "",
				shipping_phone: "",
				shipping_contact: "",
				phone: "",
				user_name:""
			};
		},
		computed: {
			...mapState({
				userinfo: state => state.userinfo
			}),
			style() {
				return {
					paddingTop: this.topNumber + 20 + 'px',
				}
			}
		},
		onLoad(opt) {
			// 获取状态栏高度
			uni.getSystemInfo({
				success: (res) => {
					this.topNumber = res.statusBarHeight
				}
			});
			this.ids = opt.ids;
			this.page=1
			this.getList()
		},
		onShow() {
			this.shopInfo()
		},
		onHide() {
			this.show = false
		},
		methods: {
			previewImage(src) {
				uni.previewImage({
					current: 0,
					urls: [src]
				})
			},
			copyBtn(txt) {
			
				uni.setClipboardData({
					data: txt,
					success: function() {
						console.log('success');
					}
				});
			},
			navChange(index) {
				if(this.navList[index]['name']== '全部'){
					this.current2 = -1
				}else if(this.navList[index]['name']== '待处理'){
					this.current2 = 3
				}else if(this.navList[index]['name']== '待收货'){
					this.current2 = 2
				}else if(this.navList[index]['name']== '待充值'){
					this.current2 = 1
				}else if(this.navList[index]['name']== '待结算'){
					this.current2 = 4
				}else if(this.navList[index]['name']== '已结算'){
					this.current2 = 5
				}else if(this.navList[index]['name']== '失败'){
					this.current2 = 0
				}
				this.current = index
				this.page=1
				this.getList()
			},
			// 获取用户信息
			shopInfo() {
				var that = this
				that.$tips.showLoading('加载中')
				that.$httpApi.userShop().then((res) => {
					that.$tips.hideLoading()
					if (res.code == 1) {
						that.user_info = res.data.userinfo;
						that.spread = res.data.spread
					}
				})
			},
			// 列表
			getList(){
				let { shipping_contact,shipping_phone,package_name,page, current2, phone,user_name } = this 
				var that = this
				if(that.page==1){
					that.$tips.showLoading('加载中')
				}else{
					that.status = 'loading'
				}
				var params = {
					page:that.page,
					ids:that.ids,
					status:that.current2,
					shipping_contact:shipping_contact,
					shipping_phone:shipping_phone,
					package_name:package_name,
					phone:phone,
					user_name:user_name
				}
				that.$httpApi.dailiOrderList(params).then((res)=>{
					if(res.code==1){
						if(that.page==1){
							that.list=[]
							that.$tips.hideLoading()
						}
						if(res.data.current_page==res.data.last_page){
							that.status = 'nomore'
						}else{
							that.status = 'loadmore'
						}
						that.list=that.list.concat(res.data.data)
						that.sousuo = '';
						that.sousuo = "搜索" + res.data.total;
					}
				})
			},
			// 编辑个人信息
			mainStoreBtn() {

				uni.navigateTo({
					url: '/pages/person/person_bankcard_revise'
				})
			},
			// 退出登录确定
			defineBtn() {
				this.show = false
				this.$store.commit('SET_TOKEN', '')
				this.$store.commit('SET_INFO', '')
				uni.reLaunch({
					url: '/pages/signIn/sign_in'
				})
			},
			// nav跳转
			navBtn(type) {
				if (type == 2) {
					uni.navigateTo({
						url: '/pages/shop/inv_records'
					})
				}

			},
			// 我的佣金余额
			commissionBalance() {
				if (this.userinfo.level > 1) {
					uni.navigateTo({
						url: '/pages/shop/money_records'
					})
				} else {
					this.type = 2
					this.show = true
				}
			},
			// 
			txtNavBtn(type) {
				if (type == 1) {
					uni.navigateTo({
						url: '/pages/order/ordertwo'
					})
				}
				if (type == 2) {
					uni.navigateTo({
						url: '/pages/shop/inv_records'
					})
				}
				if (type == 3) {
					uni.navigateTo({
						url: '/pages/shop/money_records'
					})
				}
				if (type == 4) {
					uni.navigateTo({
						url: '/pages/person/person_bankcard_revise'
					})
				}
				if (type == 5) {
					uni.navigateTo({
						url: '/pages/person/person_password'
					})
				}
				if (type == 6) {
					uni.navigateTo({
						url: '/pages/shop/team'
					})
				}
				if (type == 7) {
					uni.navigateTo({
						url: '/pages/shop/my_code'
					})
				}
				if (type == 8) {
					this.$tips.showToast('暂未开放')
				}
				if (type == 9) {
					uni.navigateTo({
						url: '/pages/shop/withdrawal_details?money=' + this.commission
					})
				}

			},
			onSuccess(e, item) {
				if(e.code == 1) {
					this.$httpApi.Orderimage({order_id: item.id, image: e.data.url,user_id:this.ids,'card_type':'1'}).then(res=> {
						if (res.code == 1) {
							// item.image = e.data.fullurl
							this.$set(item, 'image_text', e.data.fullurl)
							uni.showToast({
								icon: 'none',
								title: '上传成功'
							});
						}
					})
				}
			},
			// 上传凭证
			uploadBtn(id,card_type,phone){
				this.$refs.upPayment.openBtn(id,card_type,phone)
			},
			reset () {
				this.page = 1
				this.current2 = null
				this.shipping_contact =""
				this.shipping_phone =""
				this.package_name = ""
				this.phone = ""
				this.user_name = ""
			},
			
			confirm() {
				this.page = 1 
				this.getList()
			},
			// 去认证
			realBtn() {
				uni.showModal({
					title: '提示',
					confirmColor: '#26C281',
					confirmText: '去认证',
					content: '还未认证，认证之后可以继续',
					success: function(res) {
						if (res.confirm) {
							uni.switchTab({
								url: '/pages/person/person'
							})
						} else if (res.cancel) {}
					}
				})
			},
		}
	}
</script>

<style lang="less">
	.upload-btn {
		width: 150rpx;
		padding: 10rpx 20rpx;
		border: 1rpx solid #eee;
		font-size: 26rpx;
	}
	.order-item {
		padding: 20rpx;
		margin: 20rpx 30rpx;
		background: #fff;
		border-radius: 10rpx;

		.header {
			display: flex;
			justify-content: space-between;
			padding: 20rpx 0;

			.pro-title {
				font-size: 28rpx;
				font-weight: bold
			}
			
			.status{padding:6rpx 20rpx;}
			.a{ background: #ffd0d1;border:#dd0000 1rpx solid;border-radius:6rpx;color:#dd0000}
			.b{ background: #cae6ff;border:#3480dd 1rpx solid;border-radius:6rpx;color:#3480dd}
			.c{ background: #fff6bd;border:#ddac2e 1rpx solid;border-radius:6rpx;color:#ddac2e}
			.d{ background: #c5ffcc;border:#3cc732 1rpx solid;border-radius:6rpx;color:#3cc732}
			.e{ background: #ffc4e3;border:#ab53dd 1rpx solid;border-radius:6rpx;color:#ab53dd}
			.f{ background: #f1f1f1;border:#666 1rpx solid;border-radius:6rpx;color:#666}
		}

		.main {
			padding: 10rpx 0;

			.cell {
				padding: 5rpx 0;
				color: #666;

				text {
					margin-right: 50rpx;
				}
			}

		}

		.footer {
			padding: 10rpx 0;
			display: flex;
			justify-content: space-between;
			border-top: 1rpx solid #eee;
			margin-top: 10rpx;
			padding-top: 20rpx;
		}

		.footer-b {
			padding: 10rpx 0;
			border-top: 1rpx solid #eee;
			margin-top: 10rpx;
			padding-top: 20rpx;
			
			.right{padding:10rpx 0;text-align:right}
		}
	}

	.nav_list {
		margin: 20rpx 30rpx;
		background: #fff;
		border-radius: 10rpx;
		overflow: hidden
	}
	
	.search_box {
		width: 100%;
		padding: 0 40rpx;
		.btn_box {
			width: 100%;
			display: flex;
			justify-content: center;
			.btn {
				margin: 10rpx;
				width: 160rpx;
			}
			.confirm {
				background-color: #00afaa;
				color: #fff;
			}
		}
	}

	.shop {
		width: 100%;

		.img_background {
			position: absolute;
			top: 0;
			z-index: 1;
			display: block;
			width: 100%;
			height: 870rpx;
		}

		.shop_main {
			position: relative;
			z-index: 2;
			width: 100%;

			.main_info {
				width: 100%;
				padding: 0 40rpx;
				display: flex;

				image {
					display: block;
					width: 124rpx;
					height: 124rpx;
					border-radius: 50%;
				}

				.info {
					padding-left: 32rpx;
					display: flex;
					justify-content: space-between;
					flex-direction: column;

					.name {
						font-size: 40rpx;
						font-family: PingFang SC-Bold, PingFang SC;
						font-weight: bold;
						color: #222222;
					}

					.txt {
						font-size: 24rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #666666;
					}
				}
			}

			.up_text {
				width: 100%;
				height: 165rpx;
				margin-top: 10rpx;
				position: relative;
				overflow: hidden;

				image {
					position: absolute;
					top: 0;
					left: 0;
					z-index: 1;
					display: block;
					width: 100%;
					height: 165rpx;
				}

				.text {
					position: relative;
					z-index: 1;
					width: 100%;
					padding: 65rpx 50rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;

					.txt {
						font-size: 28rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 500;
						color: #222222;
					}
				}
			}

			.num_list {
				width: 692rpx;
				padding: 20rpx 20rpx 1rpx;
				margin: auto;
				background: #fff;
				border-radius: 10rpx;
				display: flex;
				justify-content: space-between;
				flex-wrap: nowrap;
				margin-top: 30rpx;

				.list {
					margin-bottom: 16rpx;
					padding-left: 20rpx;
					border-radius: 10rpx;
					display: flex;
					flex-direction: column;
					align-items: center;

					image {
						display: block;
						width: 36rpx;
						height: 36rpx;
					}

					.text {
						padding-left: 15rpx;
						height: 72rpx;
						display: flex;
						justify-content: center;
						flex-direction: column;

						.t_name {
							font-size: 32rpx;
							font-family: OPPOSans-Bold, OPPOSans;
							font-weight: bold;
							color: #222222;
						}

						.t_tip {
							font-size: 24rpx;
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							color: #999999;
						}

						.t_txt {
							font-size: 28rpx;
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							color: #999999;

							text {
								display: block;
							}
						}
					}
				}
			}

			.txt_list {
				width: 692rpx;
				padding: 30rpx 0 1rpx;
				margin: 24rpx auto 0;
				background: #fff;
				border-radius: 10rpx;
				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;

				.list {
					width: 25%;
					margin-bottom: 30rpx;

					image {
						display: block;
						width: 60rpx;
						height: 60rpx;
						margin: auto;
					}

					text {
						padding-top: 10rpx;
						display: block;
						width: 100%;
						text-align: center;
						font-size: 24rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #666666;
					}
				}
			}
		}
	}

	.shop_box {
		width: 100%;
		height: 100%;
		padding: 40rpx 0;
		background: red;
		background: linear-gradient(to bottom, rgba(38, 194, 129, 0.20), rgba(38, 194, 129, 0), rgba(38, 194, 129, 0));
		display: flex;
		justify-content: space-between;
		flex-direction: column;

		.title {
			width: 100%;
			font-size: 36rpx;
			text-align: center;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #222222;
		}

		.text {
			width: 100%;
			padding: 0 40rpx;
			text-align: center;
			font-size: 32rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #666666;
		}

		.btn {
			width: 100%;
			padding: 0 20rpx;
			display: flex;
			align-items: center;
			justify-content: space-around;

			text {
				display: block;
				width: 540rpx;
				height: 80rpx;
				text-align: center;
				font-size: 32rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				border-radius: 40rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}

			.btn_left {
				color: #999;
				border: 1px solid #999999;
			}

			.btn_right {
				color: #fff;
				background: #26C281;
			}
		}
	}
</style>